//
//  BaseViewController.m
//  LYPhotos
//
//  Created by 美鑫科技 on 16/5/5.
//  Copyright © 2016年 MorpLCP. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@property (nonatomic, strong) UIImageView *backGroundImage;
@property (nonatomic, strong) Theme *theme;

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initTheme];
}

#pragma mark ---------------- 主题设置相关 --------------------------
// 初始化主题
- (void)initTheme{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChanged:) name:@"themeBodyChange" object:nil];
    self.theme = [ThemeManager shareManager].theme;
}

// 设置主题
- (void)setTheme:(Theme *)theme{
    _theme = theme;
    if (theme.themeBodyColor) {
        self.view.backgroundColor = theme.themeBodyColor;
    }
    if (theme.themeBodyImage) {
        [self.backGroundImage removeFromSuperview];
        self.backGroundImage.image = theme.themeBodyImage;
        [self.view insertSubview:self.backGroundImage atIndex:0];
    }
    if (theme.themeBodyImageURL) {
        [self.backGroundImage removeFromSuperview];
        self.backGroundImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:theme.themeBodyImageURL]]];
        [self.view insertSubview:self.backGroundImage atIndex:0];
    }
}

// 主题改变通知方法
- (void)themeDidChanged:(NSNotification *)notifi{
    self.theme = [ThemeManager shareManager].theme;
}

// 设置是否隐藏状态栏
- (void)setIsHiddenStatusBar:(BOOL)isHiddenStatusBar{
    _isHiddenStatusBar = isHiddenStatusBar;
    [self prefersStatusBarHidden];
}

- (BOOL)prefersStatusBarHidden{
    if (self.isHiddenStatusBar) {
        return YES;
    } else{
        return NO;
    }
}

#pragma mark ------------- 懒加载 ---------------
- (UIImageView *)backGroundImage{
    if (!_backGroundImage) {
        _backGroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    }
    return _backGroundImage;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
